3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 Algorithm: Maximum bipartite matching, using Ford-Fulkerson method.
29 #define D(x) cout << #x " is " << x << endl
35 double d(const point
&a
, const point
&b
){
36 return sqrt( (a
.x
-b
.x
)*(a
.x
-b
.x
) + (a
.y
-b
.y
)*(a
.y
-b
.y
) );
42 int fordFulkerson(int n
, int s
, int t
){
45 fill(prev
, prev
+n
, -1);
48 while (q
.size() && prev
[t
] == -1){
51 for (int v
=0; v
<n
; ++v
){
52 if (v
!= s
&& prev
[v
] == -1 && cap
[u
][v
] > 0)
53 prev
[v
] = u
, q
.push(v
);
57 if (prev
[t
] == -1) break;
59 int bottleneck
= INT_MAX
;
60 for (int v
= t
, u
= prev
[v
]; u
!= -1; v
= u
, u
= prev
[v
]){
61 bottleneck
= min(bottleneck
, cap
[u
][v
]);
63 for (int v
= t
, u
= prev
[v
]; u
!= -1; v
= u
, u
= prev
[v
]){
64 cap
[u
][v
] -= bottleneck
;
65 cap
[v
][u
] += bottleneck
;
76 while (scanf("%d %d %d %d", &n
, &m
, &s
, &v
) == 4){
77 vector
<point
> gophers(n
);
78 vector
<point
> holes(m
);
80 for (int i
=0; i
<n
; ++i
) scanf("%lf %lf", &gophers
[i
].x
, &gophers
[i
].y
);
81 for (int i
=0; i
<m
; ++i
) scanf("%lf %lf", &holes
[i
].x
, &holes
[i
].y
);
83 memset(cap
, 0, sizeof cap
);
84 const int source
= n
+ m
, sink
= n
+ m
+ 1;
86 for (int i
=0; i
<n
; ++i
){
87 for (int j
=0; j
<m
; ++j
){
88 if (d(gophers
[i
], holes
[j
]) <= s
*v
- 1e-9){
94 for (int i
=0; i
<n
; ++i
) cap
[source
][i
] = 1;
95 for (int j
=0; j
<m
; ++j
) cap
[n
+j
][sink
] = 1;
98 int lucky
= fordFulkerson(n
+ m
+ 2, source
, sink
);
100 printf("%d\n", n
- lucky
);